﻿using System;
using System.Web;
using TS.Bussiness;
using TS.Commons;

namespace Tranco.UC
{
    public partial class Header : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string userName = Session["TracoUserName"].ToStringOrDefault();
                if(!string.IsNullOrEmpty(userName))
                {
                    lblUser.InnerText = userName+",";
                    lbtLogOn.Visible = false;
                    lbtLogOff.Visible = true;

                }
                else
                {
                    lblUser.InnerText = "";
                    lbtLogOff.Visible = false;
                    lbtLogOn.Visible = true;

                }
                ConfigurationBussiness bu = new ConfigurationBussiness();
                var config = bu.GetConfig();
                lblTitle.Text = config.WebName.ToStringOrDefault()+" - "+config.ShortAddress.ToStringOrDefault();
            }

        }

        protected void lbtLogOn_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Home.aspx");
        }

        protected void lbtLogOff_Click(object sender, EventArgs e)
        {

            Session["TracoUserName"] = null;
            Session["TracoGroupId"] = null;
            Session["TracoUserId"] = null;
            Session["TracoOwnerId"] = null;

            Session.Abandon();
            Response.Redirect("~/Home.aspx");
        }

    }
}